package com.aistar.controller;

import com.aistar.pojo.Member;
import com.aistar.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@Controller
//用来页面跳转
public class ResverController {
    @Autowired
    private MemberService memberService;


    //写游记页面的跳转
    @GetMapping("write/travel")
    public ModelAndView wrttetravel(HttpServletRequest request){

        Object ss = request.getSession().getAttribute("userId");//获得session里的用户id
        int userId = Integer.parseInt(String.valueOf(ss));
        Member member = memberService.getbyId(userId);

        ModelAndView mav = new ModelAndView();

        mav.addObject("memberall",member);
        mav.setViewName("WriteTravel/writetravel");

        return mav;
    }

    @GetMapping("traveldom/registuser")
    //用来跳转到注册页面
    public ModelAndView registTravel(HttpServletRequest request){
        ModelAndView mav = new ModelAndView();

        mav.setViewName("RegistLogin/regist");
        return mav;


    }

    //写提问界面的跳转
    @GetMapping("write/question")
    public ModelAndView wrttques(HttpServletRequest request){
        ModelAndView mav = new ModelAndView();

        Object ss = request.getSession().getAttribute("userId");//获得session里的用户id
        int userId = Integer.parseInt(String.valueOf(ss));
        Member member = memberService.getbyId(userId);

        mav.addObject("memberall",member);
        mav.setViewName("WriteQuestion/writeques");

        return mav;

    }

    //发布活动页面跳转
    @GetMapping("write/clubAc")
    public ModelAndView wrttclub(HttpServletRequest request){
        ModelAndView mav = new ModelAndView();
        Object ss = request.getSession().getAttribute("userId");//获得session里的用户id
        int userId = Integer.parseInt(String.valueOf(ss));
        Member member = memberService.getbyId(userId);

        mav.addObject("memberall",member);
        mav.setViewName("ClubList/activity_release");
        return mav;

    }

    @GetMapping("exit")
    public String exit(HttpServletRequest request){
        request.getSession().setAttribute("userId", 0);
        return "redirect:start/index";
    }
    @GetMapping("regist/normalRegist")
    public String reg(){
        return "RegistLogin/regist";
    }

    //开通vip用户的跳转
    @GetMapping("VIP")
    public ModelAndView vip (HttpServletRequest request){
        ModelAndView mav = new ModelAndView();
        Object ss = request.getSession().getAttribute("userId");//获得session里的用户id
        int userId = Integer.parseInt(String.valueOf(ss));
        Member member = memberService.getbyId(userId);

        Date date = new Date();

        mav.addObject("memberall",member);
        mav.addObject("date",date);
        mav.setViewName("traveldetails/VIP");
        return mav;
    }

}

